home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Core / Includes / USegments.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  6.4 KB  |  163 lines  |  [TEXT/MPS ]

  1. // USegments.h
  2. // Copyright © 1995-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __USEGMENTS__
  5. #define __USEGMENTS__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __MACAPPTYPES__
  10. #include "MacAppTypes.h"
  11. #endif
  12.  
  13. #if qSegments
  14.  
  15. // Toolbox
  16.  
  17. #ifndef __MEMORY__
  18. #include <Memory.h>
  19. #endif
  20.  
  21. const ResType kCode = 'CODE';                // Resource type for code
  22.  
  23. class CCodeSegment
  24. {
  25.   public:
  26.  
  27.     Size GetSize();
  28.     // GetSize returns the size, in bytes, of the segment
  29.  
  30.     void LoadMacAppSegment();
  31.     // This function patches LoadSeg. It is called from the assembly-language routine
  32.     // AMacAppLoadSeg, which is the actual patch setup by PatchTrap. AMacAppLoadSeg saves
  33.     // registers and sets up the stack by 1) allocating space for LoadMacAppSegment's
  34.     // result, and 2) pushing a copy of LoadSeg's parameter onto the stack for use by
  35.     // LoadMacAppSegment. Signals failure if the segment could not be loaded.
  36.     // NOTE: this routine requires the pascal keyword because it is called from assembler
  37.     // code that assumes pascal parameter passing conventions.
  38.  
  39.     Boolean PreloadSegmentResource();
  40.     // PreloadSegment is available to programmers who want to lock a segment at the top of
  41.     // the heap without having to call a dummy procedure in that segment. It is also
  42.     // useful for determining whether a segment can in fact be loaded before you try to
  43.     // execute code in it. PreloadSegment returns true if the segment could be loaded,
  44.     // false otherwise.
  45.     // NOTE: this routine requires the pascal keyword because it is called from assembler
  46.     // code that assumes pascal parameter passing conventions.
  47.  
  48.     void SetResidentSegment(Boolean makeResident);
  49.     // SetResidentSegment can be used to make a segment resident (or no longer resident);
  50.     // resident segments will not be unloaded by UnloadAllSegments; if a segment is made
  51.     // resident, it is also preloaded.MacApp automatically marks its resident segment as
  52.     // resident (the one containing the procedure CommandFromMenuItem); you probably should do
  53.     // UnloadAllSegments before making a segment resident, to ensure that it is locked at
  54.     // the top of the heap.
  55.  
  56.     Boolean IsSegmentLoaded();
  57.     // Returns TRUE if the segment is loaded
  58.  
  59.     Handle GetSegResource();
  60.  
  61.     Boolean IsModelFar();
  62.  
  63. #if qModelCFM
  64.     Boolean IsModelCFM();
  65. #endif
  66.  
  67.     Ptr GetFirstFunctionPointer();
  68.  
  69.     void Unload();
  70.     // Unload the segment
  71.  
  72.     Boolean ContainsAddress(void* address);
  73.     // true if the (Loaded) segment contains the address
  74.  
  75.     short fSegNum;                            // the segment number
  76.     Boolean fSegLoaderLoaded;                // true if loaded in the segment loader sense
  77.     Boolean fResidentSeg;                    // true if this seg should be resident
  78.     Boolean fInTemporaryReserve;            // true if this seg will be used in temporary reserve
  79.     Boolean fCanUnload;                        // true if we ever allow unloading for this segment
  80.     Handle fCodeSeg;                        // handle to the actual code segment
  81.     long fSegSize;                            // size of the code segment
  82.     CCodeSegment* fNextCodeSegment;            // next segment in the linked list of segments
  83.  
  84. #if qDebug
  85.     static unsigned long gHighWater;        // the largest amount of segments ever in memory
  86.     Boolean fHighWater;                        // true if this segment was present at a high-water mark
  87.     Boolean fEverLoaded;                    // true if this segment was ever loaded
  88. #endif
  89. };
  90.  
  91. //----------------------------------------------------------------------------------------
  92. // Global variable declarations.
  93. //----------------------------------------------------------------------------------------
  94.  
  95. extern CCodeSegment* gCodeSegs;
  96.     // Code segment records for all the code segments
  97.  
  98. extern Boolean gUnloadAllSegs; 
  99.     // UnloadAllSegments doesn't unload segments if this flag is false.
  100.  
  101. //----------------------------------------------------------------------------------------
  102. // These global variable declarations are meant to be private but are in the interface
  103. // just in case.
  104. //----------------------------------------------------------------------------------------
  105.  
  106. extern short pOldResFile; 
  107.     // The res file reference saved across segloads
  108.  
  109. extern Boolean pLoadSegCalledFromOwnApp;
  110.     // True if calling LoadMacAppSeg from the app and not from a _DA_ in our own heap.
  111.     // (wheels within wheels for Pete's sake!)
  112.  
  113. extern short pMaxSegNum;
  114.     // The maximum segment number
  115.  
  116.  
  117. //----------------------------------------------------------------------------------------
  118. // Initialization
  119. //----------------------------------------------------------------------------------------
  120.  
  121. void InitUSegments();
  122.     // Initializes this unit.
  123.  
  124. CCodeSegment* GetUnloadedCodeSegment(ProcPtr aProc);
  125.     // GetSegNumber returns the CCodeSegment in which aProc resides.
  126.  
  127. CCodeSegment* GetLoadedCodeSegment(void* address);
  128.     // Given an address, return the loaded CCodeSegment that contains it.
  129.  
  130. pascal UniversalProcPtr LoadMacAppSegment(short segnum);
  131.     // This function patches LoadSeg. It is called from the assembly-language routine
  132.     // AMacAppLoadSeg, which is the actual patch setup by PatchTrap. AMacAppLoadSeg saves
  133.     // registers and sets up the stack by 1) allocating space for LoadMacAppSegment's
  134.     // result, and 2) pushing a copy of LoadSeg's parameter onto the stack for use by
  135.     // LoadMacAppSegment. Signals failure if the segment could not be loaded.
  136.     // NOTE: this routine requires the pascal keyword because it is called from assembler
  137.     // code that assumes pascal parameter passing conventions.
  138.  
  139. pascal Boolean PreloadSegmentResource(short segnum);
  140.     // PreloadSegment is available to programmers who want to lock a segment at the top of
  141.     // the heap without having to call a dummy procedure in that segment. It is also
  142.     // useful for determining whether a segment can in fact be loaded before you try to
  143.     // execute code in it. PreloadSegment returns true if the segment could be loaded,
  144.     // false otherwise.
  145.     // NOTE: this routine requires the pascal keyword because it is called from assembler
  146.     // code that assumes pascal parameter passing conventions.
  147.  
  148. void LoadResidentSegments();
  149.     // Makes resident the segments whose names are included in any 'res!' resources.
  150.  
  151. void UnloadAllSegments(Boolean andPurge = FALSE);
  152.     // UnloadAllSegments unloads all segments except the blank segment or the ones marked
  153.     // resident. It is called at each iteration of the main event loop to compact memory,
  154.     // as well as other places where compacting memory is needed or desirable.
  155.     // Pass true for andPurge to purge the segments too.
  156.  
  157. Size AddSegSizes(Handle segRsrcCounted);
  158.     // Returns the total size of the code segments whose names are in the CString list
  159.     // segRrsc.
  160.  
  161. #endif // qSegments
  162. #endif // __USEGMENTS__
  163.